package com.xiguaji.tiktok.task.blogger.event;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.xiguaji.boot.eventbus.Event;
import com.xiguaji.boot.eventbus.EventBusTemplate;
import com.xiguaji.boot.eventbus.IEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 获取Aweme消息后保存对应Blogger信息
 */
@Component
public class SaveAwemeBloggerEventListener implements IEventListener<SaveAwemeBloggerEventListener.SaveAwemeBloggerEvent> {

    @Autowired
    @Lazy
    EventBusTemplate eventBusTemplate;

    @Override
    @Subscribe
    @AllowConcurrentEvents
    public void handle(SaveAwemeBloggerEvent event) {
        var saveBloggerEvent = new SaveBloggerEventListener.SaveBloggerEvent(event, event.uids, false);
        eventBusTemplate.post(saveBloggerEvent);

//        var saveBloggerFollowingEvent = new SaveBloggerFollowingEventListener.SaveBloggerFollowingEvent(saveBloggerEvent, event.uids);
//        eventBusTemplate.post(saveBloggerFollowingEvent);
//
//        var saveBloggerFollowerEvent = new SaveBloggerFollowerEventListener.SaveBloggerFollowerEvent(saveBloggerFollowingEvent, event.uids);
//        eventBusTemplate.post(saveBloggerFollowerEvent);
    }

    public static class SaveAwemeBloggerEvent extends Event {

        public SaveAwemeBloggerEvent(List<Long> uids) {
            super("SaveAwemeBlogger");
            this.uids = uids;
        }

        private List<Long> uids;
    }
}
